<template>
	<view style="padding: 30rpx;">
		<view> 异步接口</view>
		<button @click="callStorageFun(1)">setStorage</button>
		<button @click="callStorageFun(2)" type="primary" plain="true">getStorage</button>
		<button @click="callStorageFun(3)" type="primary">getStorageInfo</button>
		<button @click="callStorageFun(4)" type="warn" plain="true">RemoveStorage</button>
		<button @click="callStorageFun(5)" type="warn">ClearStorage</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:'Holmes',
				timer1:null
			}
		},
		methods: {
			callStorageFun(parm){
				console.log("callStorageFun==> parm " + parm);
				switch (parm) {
					case 1:
					uni.setStorage({
						key:'UserName',
						data:'hs',
						success() {
							console.log("UserName 存储成功");
						}
					});
					console.log("调用存储成功");
					break;
				case 2:
				uni.getStorage({
					key:'UserName',
					success:function(result){
						console.log("读取UserName成功 result.data=" + result,data);
					},
					fail(){
						console.error("读取UserName失败");
					}
				});
				break;
				case 3:
				uni.getStorageInfo({
					success:function(result){
						console.log("获取所有缓存字段:" + result.keys);
						console.log("获取占用空间" + result.currentSize);
						console.log("获取限制空间大小" + result.limitSize);
					}
				});
				break;
				case 4:
				uni.removeStorage({
					key:'UserName',
					success:function(res){
						console.log(JSON.stringify(res));
					}
				});
				break;
				case 5:
				uni.clearStorage();
				break;
				}
			}
		}
	}
</script>

<style>
button{
	margin: 20rpx;
}
</style>
